import pprint
import time
import sys
import psycopg2
from datetime import *
import datetime

##########################

def log(m):
    print('{:%Y-%m-%d %H:%M:%S}'.format(datetime.datetime.now()) + ": "+m)
    return

##########################

partisan_twitter = ['/realdonaldtrump', '/vp', '/presssec', '/potus', '/donaldtrumpjr', '/ivankatrump', '/kellyannepolls', '/nrcc', '/nancypelosi', '/teampelosi', '/whiphoyer',
          '/flotus', '/housedemocrats', '/speakerryan', '/senatemajldr', '/johncornyn', '/gopleader', '/whitehouse', '/senschumer', '/seanspicer',
          '/nrsc', '/nrcc', '/dccc','/thedemocrats', '/dscc', '/barackobama', '/joebiden', '/hillaryclinton', '/senatordurbin', '/tomperez',
          '/senaterpc', '/secretaryzinke', '/secretaryacosta', '/secretarycarson', '/secretarypompeo', '/secretarysonny', '/secretaryperry', '/secpricemd',
          '/betsydevosed', '/epascottpruitt', '/secazar', '/secnielsen', '/mickmulvaneyomb', '/secretaryross', '/stevenmnuchin1', '/secelainechao', '/johnkellywh',
          '/reince', '/stephenbannon', '/gopchairwoman', 'gop', 'dems']

partisan_non_twitter = ['dems', 'trump', 'gop', 'democrats', 'republicans', 'pence', 'obama', 'obamacare', 'republican', 'democrat', 'sessions', 'tillerson',
          'mcconnell', 'pelosi', 'schumer', 'pruitt', 'devos', 'mueller', 'collusion', 'comey', 'administration', 'kavanaugh', 'gorsuch', 'bannon', 'nielsen', 'blasey',
          'mulvaney', 'ivanka', 'kushner', 'flynn', 'comey', 'impeach', 'donald', 'actblue', 'white-house', 'ryans', 'mcconnells', 'graham-cassidy', 'cassidy-graham', 'dem-rep', 'rep-dem']

conn = psycopg2.connect(database="shoom")
c = conn.cursor()
for term in partisan_twitter:
    c.execute("UPDATE congress_urls_115 SET partisan='t' WHERE lower(actual_url) LIKE '%"+term+"%'")
conn.commit()
for term in partisan_non_twitter:
    c.execute("UPDATE congress_urls_115 SET partisan='t' WHERE lower(actual_url) LIKE '%"+term+"%' AND lower(actual_url) NOT LIKE '%twitter.com%'")
conn.commit()
c.close()
conn.close()

partisan_twitter = ['/realdonaldtrump', '/vp', '/presssec', '/potus', '/donaldtrumpjr', '/ivankatrump', '/kellyannepolls', '/nrcc', '/nancypelosi',
        '/teampelosi',  '/whiphoyer', '/flotus', '/housedemocrats', '/speakerryan', '/senatemajldr', '/johncornyn', '/gopleader', '/whitehouse',
        '/senschumer', '/seanspicer', '/nrsc', '/nrcc', '/dccc','/thedemocrats', '/dscc', '/barackobama', '/joebiden', '/hillaryclinton',
        '/senatordurbin', '/tomperez', '/senaterpc', '/secretaryzinke', '/secretaryacosta', '/secretarycarson', '/secretarypompeo', '/secretarysonny',
        '/secretaryperry', '/secpricemd', '/betsydevosed', '/epascottpruitt', '/secazar', '/secnielsen', '/mickmulvaneyomb', '/secretaryross',
        '/sbalinda', '/stevenmnuchin1', '/secelainechao', '/johnkellywh', '/reince', '/stephenbannon', '/gopchairwoman', '/dagyeates', '/comey',
        '/johnbrennan', '/senatorreid', '/speakerboehner', '/ambassadorrice', '/aglynch', '/arneduncan', '/ginaepa', '/secpritzker', '/rahmemanuel',
        '/sectomperez', '/secjacklew', '/secretaryjewell', '/ericholder', '/secburwell', '/secretaryfoxx', '/secretarycastro', '/energysecmoniz',
        '/jehjohnson', '/johnbking', '/sebelius', '/davidaxelrod', '/davidplouffe',  '/valeriejarrett', '/shaunomb', '/ambpower44', '/dennis44',
        '/mcs4biz', '/jebbush', '/jeb2016', 'tedcruz', '/scottwalker', '/johnkasich', '/berniesanders', '/carlyfiorinia', '/realbencarson',
        '/marcorubio', '/govchristie', '/chrischristie', '/randpaul', 'lindseygrahamsc', '/dwstweets', 'gop', 'dems']

partisan_non_twitter = ['dems', 'trump', 'gop', 'democrats', 'republicans', 'pence', 'obama', 'obamacare', 'republican', 'democrat', 'sessions',
        'tillerson', 'mcconnell', 'pelosi', 'schumer', 'pruitt', 'devos', 'mueller', 'collusion', 'comey', 'administration', 'kavanaugh', 'gorsuch', 'bannon',
        'nielsen', 'blasey', 'mulvaney', 'ivanka', 'kushner', 'flynn', 'comey', 'impeach', 'donald', 'actblue', 'white-house', 'ryans', 'mcconnells',
        'pelosis', 'trumps', 'schumers', 'obamas','graham-cassidy', 'cassidy-graham', 'dem-rep', 'rep-dem', 'hillary', 'hillarys', 'clinton', 'clintons',
        'jeb', 'reid', 'reids', 'boehner', 'boehners' 'wiener', 'emails', 'wikileaks', 'dnc', 'rnc', 'christie', 'walker', 'fiorina', 'garland', 'huma',
        'abedin', 'broaddrick', 'kaine', 'sit-in', 'biden', 'lynch', 'holder', 'susan-rice', 'access-hollywood', 'benghazi', 'koskinen', 'presidential-debate']

conn = psycopg2.connect(database="shoom")
c = conn.cursor()
for term in partisan_twitter:
    c.execute("UPDATE congress_urls_114 SET partisan='t' WHERE lower(actual_url) LIKE '%"+term+"%'")
conn.commit()
for term in partisan_non_twitter:
    c.execute("UPDATE congress_urls_114 SET partisan='t' WHERE lower(actual_url) LIKE '%"+term+"%' AND lower(actual_url) NOT LIKE '%twitter.com%'")
conn.commit()
c.close()
conn.close()
